// pages/subpackage/ScheduleRrder/index.js
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ScheduleOrder: [
      {
        id: 0,
        time: '2024-2-13 13:15',
        departure: '贵阳 南明区',
        destination: '北京 海淀区',
        nun: 3,
        price: '750.00'
      },
      {
        id: 1,
        time: '2024-2-13 13:15',
        departure: '贵阳 南明区',
        destination: '北京 海淀区',
        nun: 3,
        price: '750.00'
      }
    ],
    ScheduleOrder2: [],
    active: 0,
    updateBnt: ['行程预约中', '行程预约已满', '行程进进行中', '行程已结束']
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (this.data.active) {
      this.getCarPassenger()
      return
    }
    this.getitineraryPassenger()
  },
  // 乘客
  getitineraryPassenger () {
    let that = this
    let data = {
      phone: wx.getStorageSync('TwoPlusTravel').phone || '',
      page: '0'
    }
    util.request('GET', api.getitineraryPassenger, data).then(function (res) {
      let list = res || []
      if (list.length) {
        list.forEach((item) => {
          item.godate = util.timeChangeover(item.godate)
        })
      }
      that.setData({
        ScheduleOrder: list
      })
      wx.hideLoading()
    })
  },
  // 司机
  getCarPassenger () {
    let that = this
    let data = {
      phone: wx.getStorageSync('TwoPlusTravel').phone || '',
      page: '0'
    }
    util.request('GET', api.getCarPassenger, data).then(function (res) {
      let list = res || []
      if (list.length) {
        list.forEach((item) => {
          item.godate = util.timeChangeover(item.godate)
        })
      }
      that.setData({
        ScheduleOrder2: list
      })
      wx.hideLoading()
    })
  },
  onChange (e) {
    let index = e.detail.index
    if (index) {
      this.getCarPassenger()
    }else {
      this.getitineraryPassenger()
    }
    this.setData({
      active: index
    })
  },
  gotoDetil (e) {
    let id = e.currentTarget.dataset.id
    let role = e.currentTarget.dataset.role
    wx.navigateTo({
      url: '/pages/subpackage/DetailsOfTheTrip/index?id=' + id + '&role=' + role,
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    let time = setTimeout(() => {
      if (this.data.active) {
        this.getCarPassenger()
      }else {
        this.getitineraryPassenger()
      }
      wx.stopPullDownRefresh()
      clearTimeout(time)
    }, 500)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})